#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"

cmd-docker-options-add() {
  declare desc="Add a docker option to application"
  declare cmd="docker-options:add"
  [[ "$1" == "$cmd" ]] && shift 1
  declare APP="$1"

  verify_app_name "$APP"
  read -ra passed_phases <<<"$(get_phases "$2")"
  shift 2 # everything else passed is the docker option
  local passed_docker_option="$*"
  [[ -z "$passed_docker_option" ]] && dokku_log_fail "Please specify docker options to add to the phase"
  add_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
}

cmd-docker-options-add "$@"
